﻿$(function () {

    //经营资格证书上传
    $("#divJinyingzigeFile").uploadify({
        height: 30,
        buttonText: "文件选择",
        swf: '../../Content/uploadify/uploadify.swf',
        uploader: encodeURI('../../File/FileUpload?fileType=' + "对外劳务合作经营资格证书"),
        fileExt: '*.doc;*.docx', // 过滤类型
        fileDesc: '*.doc;*.docx', // 提示信息
        sizeLimit: 1024 * 1024 * 4, // 4M = 4194304
        width: 120,
        multi: false,
        onUploadSuccess: function (file, data, response) {
            var res = eval("(" + data + ")");
            if (res.Result.IsSuccess) {
                var fileId = res.Result.Message;
                $("#JinyingzigeFileId").val(fileId);
                //alert("上传成功");
                $('#' + file.id).find('.data').html('上传完毕');
            } else {
                alert(res.Result.ErrMessage);
            }
        },
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert("上传的文件数量已经超出系统限制的" + $('#divJinyingzigeFile').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#divJinyingzigeFile').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    alert("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    alert("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        }
    });

    //营业执照上传
    $("#divYinyezhizhaoFile").uploadify({
        height: 30,
        buttonText: "文件选择",
        swf: '../../Content/uploadify/uploadify.swf',
        uploader:  encodeURI('../../File/FileUpload?fileType=' + "营业执照"),
        fileExt: '*.doc;*.docx', // 过滤类型
        fileDesc: '*.doc;*.docx', // 提示信息
        sizeLimit: 1024 * 1024 * 4, // 4M = 4194304
        width: 120,
        multi: false,
        onUploadSuccess: function (file, data, response) {
            var res = eval("(" + data + ")");
            if (res.Result.IsSuccess) {
                var fileId = res.Result.Message;
                $("#YinyezhizhaoFileId").val(fileId);
                // alert("上传成功");
                $('#' + file.id).find('.data').html('上传完毕');
            } else {
                alert(res.Result.ErrMessage);
            }
        },
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert("上传的文件数量已经超出系统限制的" + $('#divJinyingzigeFile').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#divJinyingzigeFile').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    alert("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    alert("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        }
    });

    //募集要項上传
    $("#divMujiyaoxiangFile").uploadify({
        height: 30,
        buttonText: "文件选择",
        swf: '../../Content/uploadify/uploadify.swf',
        uploader:  encodeURI('../../File/FileUpload?fileType=' + "募集要项"),
        fileExt: '*.doc;*.docx', // 过滤类型
        fileDesc: '*.doc;*.docx', // 提示信息
        sizeLimit: 1024 * 1024 * 4, // 4M = 4194304
        width: 120,
        multi: false,
        onUploadSuccess: function (file, data, response) {
            var res = eval("(" + data + ")");
            if (res.Result.IsSuccess) {
                var fileId = res.Result.Message;
                $("#MujiyaoxiangFileId").val(fileId);
                //alert("上传成功");
                $('#' + file.id).find('.data').html('上传完毕');
            } else {
                alert(res.Result.ErrMessage);
            }
        },
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert("上传的文件数量已经超出系统限制的" + $('#divMujiyaoxiangFile').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#divMujiyaoxiangFile').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    alert("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    alert("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        }
    });

    //头像上传
    $("#divResumeImageBtn").uploadify({
        queueID: "some_file_queue",//目的隐藏进度条
        height: 30,
        buttonClass: "ResumeImageBtn",
        buttonText: "选择头像",
        swf: '../Content/uploadify/uploadify.swf',
        uploader: encodeURI('../File/FileUpload?fileType=' + "登记表头像"),
        fileExt: '*.jpg;*.gif;*.png', // 过滤类型
        fileDesc: '*.jpg;*.gif;*.png', // 提示信息
        sizeLimit: 1024 * 1024 * 4, // 4M = 4194304
        width: 144,
        multi: false,
        onUploadSuccess: function (file, data, response) {
            var res = eval("(" + data + ")");
            if (res.Result.IsSuccess) {
                var fileId = res.Result.Message;
                $("#ImageId").val(fileId);
               // alert("上传成功");
                ShowPic(fileId)
            } else {
                alert(res.Result.ErrMessage);
            }
        }
    });



    //图片展示
    function ShowPic(id) {
        if (id) {
            id = id.replace('.', '_');
            var picPath = "../File/GetPic/" + id;
            var $picContent = $("#divPicContent");
            $picContent.attr("src", picPath);
        }
    }

    if ($("#ImageId").val()) {
        ShowPic($("#ImageId").val());
    }

});